package org.dtrd.modules.achievement.entity.po;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import org.dtrd.common.util.DateUtils;
import org.dtrd.modules.achievement.entity.bean.PatientSigninPlan;
import org.dtrd.modules.achievement.entity.bean.SigninPlan;

import javax.persistence.*;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Table(name = "dtrd_ent_rd_signin_plan")
public class DtrdEntRdSigninPlan {
    @Id
    @Column(name = "data_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    private Integer dataId;

    @Column(name = "patient_id")
    private Integer patientId;

    @Column(name = "doctor_id")
    private Integer doctorId;

    /**
     * 开始日期
     */
    @Column(name = "sign_in_startdate")
    private Date signInStartdate;

    /**
     * 打卡模版id
     */
    private Integer signInTemplateId;

    /**
     * 打卡状态, 0-未开始, 1-使用中, 2-已结束, 4-暂停中
     */
    private Integer signInStatus;

    /**
     * 结束日期
     */
    @Column(name = "sign_in_enddate")
    private Date signInEnddate;

    @Column(name = "create_time")
    private Date createTime;

    @TableLogic
    @Column(name = "is_del")
    private Integer isDel;

    /**
     * 工作日json格式
     */
    @Column(name = "sign_in_json_workingday")
    private String signInJsonWorkingday;

    /**
     * 周末json格式
     */
    @Column(name = "sign_in_json_weekend")
    private String signInJsonWeekend;

    /**
     * 周一计划
     */
    @Column(name = "sign_in_json_monday")
    private String signInJsonMonday;

    /**
     * 周二计划
     */
    @Column(name = "sign_in_json_tuesday")
    private String signInJsonTuesday;

    /**
     * 周三计划
     */
    @Column(name = "sign_in_json_wednesday")
    private String signInJsonWednesday;

    /**
     * 周四计划
     */
    @Column(name = "sign_in_json_thursday")
    private String signInJsonThursday;

    /**
     * 周五计划
     */
    @Column(name = "sign_in_json_friday")
    private String signInJsonFriday;

    /**
     * 周六计划
     */
    @Column(name = "sign_in_json_saturday")
    private String signInJsonSaturday;

    /**
     * 周日计划
     */
    @Column(name = "sign_in_json_sunday")
    private String signInJsonSunday;

    /**
     * 备注
     */
    private String remark;

    /**
     * 操作人
     */
    private String updateBy;

    /**
     * @return data_id
     */
    public Integer getDataId() {
        return dataId;
    }

    /**
     * @param dataId
     */
    public void setDataId(Integer dataId) {
        this.dataId = dataId;
    }

    /**
     * @return patient_id
     */
    public Integer getPatientId() {
        return patientId;
    }

    /**
     * @param patientId
     */
    public void setPatientId(Integer patientId) {
        this.patientId = patientId;
    }

    /**
     * @return doctor_id
     */
    public Integer getDoctorId() {
        return doctorId;
    }

    /**
     * @param doctorId
     */
    public void setDoctorId(Integer doctorId) {
        this.doctorId = doctorId;
    }

    /**
     * 获取开始日期
     *
     * @return sign_in_startdate - 开始日期
     */
    public Date getSignInStartdate() {
        return signInStartdate;
    }

    /**
     * 设置开始日期
     *
     * @param signInStartdate 开始日期
     */
    public void setSignInStartdate(Date signInStartdate) {
        this.signInStartdate = signInStartdate;
    }

    /**
     * 获取结束日期
     *
     * @return sign_in_enddate - 结束日期
     */
    public Date getSignInEnddate() {
        return signInEnddate;
    }

    /**
     * 设置结束日期
     *
     * @param signInEnddate 结束日期
     */
    public void setSignInEnddate(Date signInEnddate) {
        this.signInEnddate = signInEnddate;
    }

    /**
     * @return create_time
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param createTime
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return is_del
     */
    public Integer getIsDel() {
        return isDel;
    }

    /**
     * @param isDel
     */
    public void setIsDel(Integer isDel) {
        this.isDel = isDel;
    }

    /**
     * 获取工作日json格式
     *
     * @return sign_in_json_workingday - 工作日json格式
     */
    public String getSignInJsonWorkingday() {
        return signInJsonWorkingday;
    }

    /**
     * 设置工作日json格式
     *
     * @param signInJsonWorkingday 工作日json格式
     */
    public void setSignInJsonWorkingday(String signInJsonWorkingday) {
        this.signInJsonWorkingday = signInJsonWorkingday;
    }

    /**
     * 获取周末json格式
     *
     * @return sign_in_json_weekend - 周末json格式
     */
    public String getSignInJsonWeekend() {
        return signInJsonWeekend;
    }

    /**
     * 设置周末json格式
     *
     * @param signInJsonWeekend 周末json格式
     */
    public void setSignInJsonWeekend(String signInJsonWeekend) {
        this.signInJsonWeekend = signInJsonWeekend;
    }

    /**
     * 获取周一计划
     *
     * @return sign_in_json_monday - 周一计划
     */
    public String getSignInJsonMonday() {
        return signInJsonMonday;
    }

    /**
     * 设置周一计划
     *
     * @param signInJsonMonday 周一计划
     */
    public void setSignInJsonMonday(String signInJsonMonday) {
        this.signInJsonMonday = signInJsonMonday;
    }

    /**
     * 获取周二计划
     *
     * @return sign_in_json_tuesday - 周二计划
     */
    public String getSignInJsonTuesday() {
        return signInJsonTuesday;
    }

    /**
     * 设置周二计划
     *
     * @param signInJsonTuesday 周二计划
     */
    public void setSignInJsonTuesday(String signInJsonTuesday) {
        this.signInJsonTuesday = signInJsonTuesday;
    }

    /**
     * 获取周三计划
     *
     * @return sign_in_json_wednesday - 周三计划
     */
    public String getSignInJsonWednesday() {
        return signInJsonWednesday;
    }

    /**
     * 设置周三计划
     *
     * @param signInJsonWednesday 周三计划
     */
    public void setSignInJsonWednesday(String signInJsonWednesday) {
        this.signInJsonWednesday = signInJsonWednesday;
    }

    /**
     * 获取周四计划
     *
     * @return sign_in_json_thursday - 周四计划
     */
    public String getSignInJsonThursday() {
        return signInJsonThursday;
    }

    /**
     * 设置周四计划
     *
     * @param signInJsonThursday 周四计划
     */
    public void setSignInJsonThursday(String signInJsonThursday) {
        this.signInJsonThursday = signInJsonThursday;
    }

    /**
     * 获取周五计划
     *
     * @return sign_in_json_friday - 周五计划
     */
    public String getSignInJsonFriday() {
        return signInJsonFriday;
    }

    /**
     * 设置周五计划
     *
     * @param signInJsonFriday 周五计划
     */
    public void setSignInJsonFriday(String signInJsonFriday) {
        this.signInJsonFriday = signInJsonFriday;
    }

    /**
     * 获取周六计划
     *
     * @return sign_in_json_saturday - 周六计划
     */
    public String getSignInJsonSaturday() {
        return signInJsonSaturday;
    }

    /**
     * 设置周六计划
     *
     * @param signInJsonSaturday 周六计划
     */
    public void setSignInJsonSaturday(String signInJsonSaturday) {
        this.signInJsonSaturday = signInJsonSaturday;
    }

    /**
     * 获取周日计划
     *
     * @return sign_in_json_sunday - 周日计划
     */
    public String getSignInJsonSunday() {
        return signInJsonSunday;
    }

    /**
     * 设置周日计划
     *
     * @param signInJsonSunday 周日计划
     */
    public void setSignInJsonSunday(String signInJsonSunday) {
        this.signInJsonSunday = signInJsonSunday;
    }

    public Integer getSignInTemplateId() {
        return signInTemplateId;
    }

    public void setSignInTemplateId(Integer signInTemplateId) {
        this.signInTemplateId = signInTemplateId;
    }

    public Integer getSignInStatus() {
        return signInStatus;
    }

    public void setSignInStatus(Integer signInStatus) {
        this.signInStatus = signInStatus;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public DtrdEntRdSigninPlan fromSigninPlan(SigninPlan request) {
        patientId = request.getPatientId();
        doctorId = request.getDoctorId();
        signInJsonWorkingday = request.getSignInJsonWorkingday();
        signInJsonWeekend = request.getSignInJsonWeekend();
        signInJsonMonday = request.getSignInJsonMonday();
        signInJsonTuesday = request.getSignInJsonTuesday();
        signInJsonWednesday = request.getSignInJsonWednesday();
        signInJsonThursday = request.getSignInJsonThursday();
        signInJsonFriday = request.getSignInJsonFriday();
        signInJsonSaturday = request.getSignInJsonSaturday();
        signInJsonSunday = request.getSignInJsonSunday();
        signInStartdate = request.getSignInStartdate();
        signInEnddate = request.getSignInEnddate();
        return this;
    }

    public DtrdEntRdSigninPlan parseFromTemplate(DtrdEntRdSigninTemplate template) {
        signInJsonMonday = template.getSignInJsonMonday();
        signInJsonTuesday = template.getSignInJsonTuesday();
        signInJsonWednesday = template.getSignInJsonWednesday();
        signInJsonThursday = template.getSignInJsonThursday();
        signInJsonFriday = template.getSignInJsonFriday();
        signInJsonSaturday = template.getSignInJsonSaturday();
        signInJsonSunday = template.getSignInJsonSunday();
        return this;
    }

    /**
     * 获取传入的 Json 格式部分, 去掉多余字段
     */
    public DtrdEntRdSigninPlan getSignInPlanJson(PatientSigninPlan plan) {
        signInJsonMonday = deleteProperty(plan.getSignInJsonMonday());
        signInJsonTuesday = deleteProperty(plan.getSignInJsonTuesday());
        signInJsonWednesday = deleteProperty(plan.getSignInJsonWednesday());
        signInJsonThursday = deleteProperty(plan.getSignInJsonThursday());
        signInJsonFriday = deleteProperty(plan.getSignInJsonFriday());
        signInJsonSaturday = deleteProperty(plan.getSignInJsonSaturday());
        signInJsonSunday = deleteProperty(plan.getSignInJsonSunday());
        return this;
    }

    public String deleteProperty(List<JSONObject> jsonArray) {
        for (JSONObject object : jsonArray) {
            object.remove("item_id");
            object.remove("item");
        }
        return Arrays.toString(jsonArray.toArray());
    }

    public DtrdEntRdSigninPlan init() {
        isDel = 0;
        createTime = new Date();
        return this;
    }

    @Override
    public String toString() {
        return "DtrdEntRdSigninPlan{" +
                "dataId=" + dataId +
                ", patientId=" + patientId +
                ", signInStartdate=" + signInStartdate +
                ", signInStatus=" + signInStatus +
                ", signInEnddate=" + signInEnddate +
                '}';
    }
}